<?php
/**
 * ǰ̨�û�������
 *
 * PHP Version 5
 *
 * @package    Shop
 * @subpackage Models
 * @author     v.k <vampirekiss@zhen.ta.ma.de.niu.bi>
 * @copyright  2010 Xingchangxinda Inc.
 * @version    SVN:$Id$
 */

namespace Project\Apps\Ecga\Library;

use \Framework\System\Abstractions\User;
use \Framework\System\Abstractions\UserException;
use \Framework\System\Abstractions\UserManager as BaseUserManager;
use \Framework\System\Helper\HttpRequest;
use \Framework\Mapper\FieldException;


/**
 * �û�������
 *
 * @package   Shop
 * @author    v.k <vampirekiss@zhen.ta.ma.de.niu.bi>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   Release: 0.1
 */
class UserManager extends BaseUserManager
{
    public function __construct($model)
    {
        $this->userModel = $model;
        $this->model = model($model);
    }
    /**
     * ע���û�
     *
     * @param string $account  �û��˺�
     * @param string $password �û�����
     * @param string $salt     ����
     * @param array  $profile  �û�����
     *
     * @return bool
     * @throws UserException
     */
    public function register($account, $password, $salt, $profile = array())
    {
        return true;
    }

    /**
     * �ж��û��Ƿ����
     *
     * @param string $account �û��˺�
     *
     * @return bool
     */
    public function userExists($account)
    {
        return $this->model->getUser($account) != null;
    }

    /**
     * �����û�����
     *
     * @param string $password �û�����
     * @param string $salt     ����
     *
     * @return bool
     */
    public function encryptPassword($password, $salt)
    {
        return $this->model->encrypt($password, $salt);
    }

    /**
     * ����û��˺Ż�ȡʵ��
     *
     * @param string $account �û��˺�
     *
     * @return Entity
     */
    public function getEntityByAccount($account)
    {
        static $entities = array();
        if (!isset($entities[$account])) {
            $entities[$account] = $this->model->getUser($account);
        }
        return $entities[$account];
    }

    /**
     * ����û�ID��ȡʵ��
     *
     * @param int $id �û�ID
     *
     * @return Entity
     * @author v.k
     */
    public function getEntityById($id)
    {
        static $entity = null;
        if (null === $entity) {
            $entity = $this->model->get($id);
        }

        return $entity;
    }
}
